#include "game_snake.h"
#include "ui_game_snake.h"
#include<gameselect.h>
#include"gameroom.h"
#include<QPixmap>
#include<QPainter>
#include<QIcon>
#include<QPushButton>
#include<QSound>//添加音效
#include<QTime>

game_snake::game_snake(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::game_snake)
{
    ui->setupUi(this);


    //设置窗口大小
    this->setFixedSize(1000,800);

    this->setWindowIcon(QIcon(":res/WidgetLogo.png"));
    this->setWindowTitle("贪吃蛇大作战");

    QFont fort("华文琥珀",24);
    QPushButton* star=new QPushButton(this);
    //设置字体样式
    star->setFont(fort);
    star->move(430,530);
    star->setText("开始游戏");
    //去边框
    star->setStyleSheet("QPushButton{border:0px;}");

    GameSelect* gameselect=new GameSelect;
    connect(star,&QPushButton::clicked,[=](){
        this->close();
        gameselect->setGeometry(this->geometry());
        gameselect->show();

        //添加音效
        QSound::play(":res/clicked.wav");
    });


}

game_snake::~game_snake()
{
    delete ui;
}

void game_snake::paintEvent(QPaintEvent *event)
{
    //实例化画家
    QPainter painter(this);

    QPixmap pic(":res/game_hall.png");

    painter.drawPixmap(0,0,this->width(),this->height(),pic);
}

